package main

import (
	"fmt"
	"gopkg.in/src-d/go-git.v4"
	"gopkg.in/src-d/go-git.v4/plumbing/object"
	"time"
)

// Basic example of how to commit changes to the current branch to an existing
// repository.
func main() {
	directory := "file"

	// Opens an already existing repository.
	r, err := git.PlainOpen(directory)
	if err != nil {
		fmt.Println(err)
	}
	w, err := r.Worktree()
	// Commits the current staging area to the repository, with the new file
	// just created. We should provide the object.Signature of Author of the
	// commit.
	commit, err := w.Commit("example go-git commit", &git.CommitOptions{
		Author: &object.Signature{
			Name:  "John Doe",
			Email: "john@doe.org",
			When:  time.Now(),
		},
	})
	obj, err := r.CommitObject(commit)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(obj)

	// push using default options
	err = r.Push(&git.PushOptions{})
}
